package com.elysium.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.elysium.pojo.vo.LoginVo;
import com.elysium.sms.AliyunSmsService;
import com.elysium.pojo.param.RegisterSaveLoginParam;
import com.elysium.result.R;
import com.elysium.service.ILoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.UnsupportedEncodingException;

@Tag(name = "小程序登录表",description = "小程序登录表")
@RestController
@RequestMapping("/app/login")
public class AppLoginController {

    @Autowired
    public ILoginService loginService;
    @Autowired
    private AliyunSmsService smsService;

    @Operation( summary= "小程序登录",description = "小程序登录接口")
    @PostMapping (value = "/wxLogin/{openIdCode}/{type}")
    @SaIgnore
    public R<LoginVo> wxLogin(@PathVariable("openIdCode") String code, @PathVariable("type") Integer type) {
        return R.success(loginService.wxLogin(code, type));
    }

    @Operation( summary= "保存Login",description = "基础对象保存接口")
    @Parameter(name = "login",description = "保存的对象",required = true)
    @PostMapping
    @SaIgnore
    public R<Void> save(@RequestBody @Valid RegisterSaveLoginParam registerSaveLoginParam){
        loginService.registerSaveLogin(registerSaveLoginParam);
        return R.success();
    }

    @Operation( summary= "短信发送",description = "短信发送接口")
    @GetMapping(value = "/phoneVerify/{mobile}")
    @SaIgnore
    public boolean  send(@PathVariable("mobile") String mobile) throws UnsupportedEncodingException {
        return smsService.send(mobile);
    }

}
